#pragma once
#include "..\utils\PlainTextReader.h"
#include <string>
#include "..\particles\ParticleSystem.h"
#include "..\lib\container\List.h"
#include "..\pipeline\DeclarationManager.h"
namespace ds {

enum AffectorType {
	AT_LIFE_TIME_AFFECTOR,
	AT_POSITION_AFFECTOR,
	AT_ALPHA_AFFECTOR,
	AT_ROTATON_AFFECTOR,
	AT_WIGGLE_AFFECTOR,
	AT_COLOR_FADE_AFFECTOR,
	AT_SIZE_AFFECTOR,
	AT_SIZE_SINE_AFFECTOR,
	AT_RADIAL_VELOCITY_AFFECTOR
};

class ParticleAffectorDecl : public ResourceDeclaration {

public:
	ParticleAffectorDecl() : ResourceDeclaration("Affector") {}
	virtual ~ParticleAffectorDecl() {}
	void create(ParticleSystem* particleSystem);
	void parseCategory(Category* category) {}
	DeclarationType getType() const {
		return DT_PARTICLE_AFFECTOR;
	}
	float getData(uint32 index) {
		return m_Data[index];
	}
	void setData(uint32 index,float value) {
		m_Data[index] = value;
	}
	AffectorType getAffectorType() const {
		return m_AffectorType;
	}
	void setAffectorType(AffectorType affectorType) {
		m_AffectorType = affectorType;
	}
private:
	Vec2 getVec2(uint32 index) {
		return Vec2(m_Data[index],m_Data[index+1]);
	}
	AffectorType m_AffectorType;
	float m_Data[20];
};



class ParticleSystemDecl : public ResourceDeclaration {

enum EmitterType {
	ET_BOX,
	ET_RING,
	ET_POINT
};

public:
	ParticleSystemDecl(const std::string& name) : ResourceDeclaration(name) , m_Name(name) {}
	virtual ~ParticleSystemDecl();
	void parseCategory(Category* category);
	DeclarationType getType() const {
		return DT_PARTICLESYSTEM;
	}
	ParticleSystem* create();
	std::string& getName() {
		return m_Name;
	}
	void setTexture(const std::string& texture) {
		m_Texture = texture;
	}
	std::string& getTexture() {
		return m_Texture;
	}
	std::string& getLayer() {
		return m_Layer;
	}
	void setLayer(const std::string& layer) {
		m_Layer = layer;
	}
	void addAffectorDeclaration(ParticleAffectorDecl* decl) {
		m_AffectorDeclarations.append(decl);
	}
	List<ParticleAffectorDecl*>& getAffectorDeclarations() {
		return m_AffectorDeclarations;
	}
private:
	std::string m_Name;
	std::string m_Texture;
	std::string m_Layer;
	EmitterType m_EmitterType;
	Vec2 size;	
	Rect textureRect;
	int total;
	float ttl;
	float initialSize;
	Color color;
	bool rotate;
	float radius;
	List<ParticleAffectorDecl*> m_AffectorDeclarations;
};

class ParticleSystemDeclParser : public DeclarationParser {

public:
	ParticleSystemDeclParser() : DeclarationParser() {}
	virtual ~ParticleSystemDeclParser() {}
	ResourceDeclaration* loadTextFile(const ResourceFile& resourceFile);
	void loadTextFile(const ResourceFile& resourceFile,DeclarationManager* declarationManager) {}
	void createResource(ResourceDeclaration* declaration);
	DeclarationType getType() const {
		return DT_PARTICLESYSTEM;
	}
	bool isSupported(const std::string& fileEnding) const {
		return fileEnding == ".particles";
	}
	bool isReloadable() const {
		return true;
	}
private:
	std::string m_Texture;
	std::string m_Layer;
};

}
